package com.hz.blogservice.mapper;

import com.hz.blogservice.model.entity.BlogEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BlogMapper {

    @Insert("insert into blogs values (null,#{title},#{content},#{author_id},#{author_username},#{author_realname},#{publish_time},#{is_anonymous},#{anonymous_name})")
    int addBlog(BlogEntity blogEntity);

    @Select("select * from blogs where id =#{id}")
    BlogEntity selectBlog(@Param("id") Integer id);

    @Select("select * from blogs")
    List<BlogEntity> allBlogs();

    @Delete("delete from blogs where id=#{id}")
    int delById(@Param("id") Integer id);

    @Update("update blogs set title=#{title} , content=#{content} where id =#{id}")
    int editBlog(@Param("id") Integer id,@Param("title") String title ,@Param("content") String content);

    @Select("select * from blogs where auther_id=#{user_id}")
    List<BlogEntity> myBlogs(@Param("userId") Integer userId);


}
